import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import store from './store'
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';
//进度条插件
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
//弹幕插件
import { vueBaberrage } from 'vue-baberrage'
//滑动验证码
import SlideVerify from 'vue-monoplasty-slide-verify'
// 导入css样式
import './assets/css/iconfont.css';
import './assets/css/index.css'
import './assets/css/global.css'
import './assets/css/me.css'
import VueParticles from 'vue-particles'
// 引入文件
import hljs from "highlight.js";
import "highlight.js/styles/atom-one-dark.css"; //样式文件

// 导入支持markdown编辑器样式
 import mavonEditor from 'mavon-editor'
 import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)
Vue.use(SlideVerify)
Vue.directive('highlight',function (el){
  let blocks = el.querySelectorAll('pre code');
  blocks.forEach(block => {
    hljs.highlightBlock(block)
  })
})
Vue.use(vueBaberrage)
// 全局配置baseURL
//axios.withCredentials = true
axios.defaults.baseURL ='http://localhost:9527' //'http://localhost:3000'
//axios.defaults.baseURL = '/music'
// 将axios改写为Vue的原型属性
Vue.prototype.$http = axios;

Vue.use(ElementUI);
Vue.use(store);
// Vue.use(mavonEditor);

Vue.use(VueParticles)
Vue.config.productionTip = false

// 在request拦截器中展示进度条
axios.interceptors.request.use(config => {
  // console.log(config)
  NProgress.start()
    config.headers.Authorization = window.sessionStorage.getItem('token')
  // 在最后必须 return config
  return config
})

// 在 response 拦截器中，隐藏进度条 NProgress.done()
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

axios.interceptors.response.use(
  function (response) {
    switch (response.data.code) {
      case 51001:
        Vue.prototype.$message.error("token已经过期，请重新登录")
        // 清空用户菜单
        resetRouter();
        window.sessionStorage.clear()
        vueInstance.$store.commit('logout')
        vueInstance.$router.push("/login")
    }
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
